﻿$.MGJ.OutBank = [];

(function () {
    var _this = $.MGJ.OutBank;
    $.extend($.MGJ.OutBank, {

        // 显示详细数据
        Dialog_OutShowDataObj: null,
        Dialog_OutShowData: function (obj) {
            var id = $(obj).attr("ID");
            this.Dialog_OutShowDataObj = $.L.dialog({
                url: ACTION_URL("OutShowData", "FleeGoods") + "?id=" + id,
                title: "详细数据",
                width: 1100,
                height: 'auto',
                buttons: {
                    "button_cancel": {
                        type: 'primary',
                        text: '返回',
                        click: 'MODALMISS'
                    }
                },
            });
        },
        // 产品出库
        Dialog_OutInfoObj: null,
        Dialog_OutInfo: function () {
            this.Dialog_OutInfoObj = $.L.dialog({
                url: ACTION_URL("OutInfo", "FleeGoods"),
                title: "输入物流码信息",
                width: 800,
                height: 'auto',
               
            });
        },

        // 出库编辑
        Dialog_EditOutObj: null,
        Dialog_EditOut: function (obj) {
            var TheText;
            var index_1 = $("#tableList_right tr").index($(obj).parent().parent());
            $("#tableList tr").each(function () {
                var index_2 = $(this).index();
                if (index_2 == index_1) {
                    TheText = $(this).find(".Status").text();
                }
            })
            var id = $(obj).attr("ID");
            if (TheText == "待编辑" || TheText == undefined) {
                this.Dialog_EditOutObj = $.L.dialog({
                    url: ACTION_URL("EditOut", "FleeGoods") + "?id=" + id,
                    title: "出库信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '保存',
                            click: function () {
                                if ($("#ProductName").val() != "") {
                                    var bootstrapValidator = $("#form").data('bootstrapValidator').validate();//触发全部验证
                                    if (bootstrapValidator.isValid()) {
                                        _this.Ajax_EditStorage();
                                        $(".btn-primary").attr("disabled", true);
                                    }
                                    else {
                                        $.L.msgError("请检查数据格式！");
                                    };
                                } else {
                                    $.L.msgError("产品不存在")
                                }
                            }
                        },
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditOutObj.close();
                                _this.Ajax_PageList(1);
                            }
                        }
                    },
                });
            } else {
                this.Dialog_EditOutObj = $.L.dialog({
                    url: ACTION_URL("EditOut", "FleeGoods") + "?id=" + id,
                    title: "出库信息",
                    width: 800,
                    height: 'auto',
                    buttons: {
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: function () {
                                _this.Dialog_EditOutObj.close();
                                _this.Ajax_PageList(1);
                            }
                        }
                    },
                });
            }
        },

    });
})(jQuery);
(function () {
    var _index = 1;
    var _this = $.MGJ.OutBank;
    $.extend($.MGJ.OutBank, {
        //多条件查询
        Ajax_PageList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#Key").val());
            $.L.ajaxHandle({
                url: ACTION_URL("OutPageList", "FleeGoods") + "?pageindex=" + pageIndex,
                data: $("#SearchForm").serialize(),
                success: function (response) {
                    $("#tableList").L_bindingDataList(response);
                    $("#tableList_left").L_bindingDataList(response);
                    $("#tableList_right").L_bindingDataList(response);
                    for (var i = 0; i < response.PageData.length; i++) {
                        var TheText = response.PageData[i].statusText
                        if (TheText == "待编辑" || TheText == "") {
                            $("#tableList_right tr").eq(i).find("td a:first-child").text("编辑");
                        } else {
                            //   $("#tableList_right tr").eq(i).find("td a:first-child").text("查看");
                            $("#tableList_right tr").eq(i).find("td a:first-child").attr("style", "visibility:hidden;")
                        }
                    }
                }
            });
        },
        //编辑
        Ajax_EditStorage: function () {
            $.L.ajaxHandle({
                url: ACTION_URL("EditStorageInfo", "FleeGoods"),
                data: $("#form").serialize(),
                success: function (response) {
                    if (response > 0) {
                        $.L.msgSuccess("操作成功");
                        _this.Dialog_EditOutObj.close();
                        _this.Ajax_PageList(1);
                    }
                    else {
                        $.L.msgSuccess("操作失败");
                    }
                }
            });
        },
        //删除
        Ajax_DelWarehousInfo: function (obj) {
            if (confirm("确定要删除吗？")) {
                var id = $(obj).attr("ID");
                $.L.ajaxHandle({
                    url: ACTION_URL("DelWarehousInfo", "FleeGoods"),
                    data: {
                        id: id
                    },
                    success: function (response) {
                        if (response > 0) {
                            _this.Ajax_PageList(_index);
                            $.L.msgSuccess("操作成功");
                        }
                        else {
                            $.L.msgSuccess("操作失败");
                        }
                    }
                });
            }
        },
        //填写物流码
        Ajax_LittleCode: function () {
            var BoxCode = $("#SingleCodes").val();
            $.L.ajaxHandle({
                url: ACTION_URL("OutLittleCode", "FleeGoods") + "?BoxCode=" + BoxCode,
                data: {
                    BoxCode: BoxCode
                },
                success: function (response) {
                    var data = eval("(" + response + ")");
                    if (data.id > 0) {
                        _this.Dialog_OutInfoObj.close();
                        _this.Dialog_EditOut({ 'ID': data.id });
                    }
                    else {
                        $.L.msgError(data.text);
                    }
                }
            });
        },
    });
})(jQuery);
(function () {
    var _this = $.MGJ.OutBank;
    $.extend($.MGJ.OutBank, {
    });
})(jQuery);